//
//  ZDPresentationController.m
//  OCSinaWeiBo
//
//  Created by Apple on 15/11/11.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDPresentationController.h"

NSString *const ZDPopoverViewControllerDismissNotification = @"ZDPopoverViewControllerDismissNotification";

@implementation ZDPresentationController

//重写方法
- (void)containerViewWillLayoutSubviews
{
    [super containerViewWillLayoutSubviews];
    
    //拿到modal视图 并设置frame
    self.presentedView.frame = CGRectMake(100, 56, 200, 300);
    
    //拿到容器视图
    UIView *transitionView = self.containerView;
    
    //为容器视图添加点击事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [transitionView addGestureRecognizer:tap];
    
    //设置容器视图的背景颜色  0表示全黑  然后设置0.2的透明度
    transitionView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
}


- (void)tap
{
    //modal控制器退出
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
    
    //发送通知
    [[NSNotificationCenter defaultCenter] postNotificationName:ZDPopoverViewControllerDismissNotification object:self];
}


@end
